﻿using System;
using Autofac;
using System.Collections.Generic;
using System.Web;
using SlamCms.Services;
using Autofac.Integration.Web;

namespace SlamCms.SharePoint.Services
{
	public class AutofacSlamCmsSharePointDependencyResolver : ContainerProvider, IDependencyResolver
	{	
		public AutofacSlamCmsSharePointDependencyResolver(IContainer container) :
			base(container)
        {	
        }

		public AutofacSlamCmsSharePointDependencyResolver(IContainer container, Action<ContainerBuilder> configurationAction) :
			base(container, configurationAction)
		{
		}

		public object GetService(Type serviceType)
		{
			return RequestLifetime.ResolveOptional(serviceType);
		}

		public IEnumerable<object> GetServices(Type serviceType)
		{
			var enumerableServiceType = typeof(IEnumerable<>).MakeGenericType(serviceType);
			var instance = RequestLifetime.Resolve(enumerableServiceType);
			return (IEnumerable<object>)instance;
		}
	}
}
